<template>
  <header class="header">
    <div class="container header-content">
      <div class="logo">
        <router-link to="/">
          <img src="/vite.svg" alt="Vue Logo" class="logo-img" />
          <span class="logo-text">File To Code</span>
        </router-link>
      </div>
      
      <nav class="nav">
        <router-link to="/" class="nav-item" :class="{ active: $route.path === '/' }">
          首页
        </router-link>
        <router-link to="/storage" class="nav-item" :class="{ active: $route.path.startsWith('/storage') }">
          文件货柜
        </router-link>
        <router-link to="/transfer" class="nav-item" :class="{ active: $route.path.startsWith('/transfer') }">
          文件速递
        </router-link>
        <button class="theme-toggle" @click="toggleTheme" :title="isDarkMode ? '切换到亮色模式' : '切换到暗色模式'">
          <span class="theme-icon">{{ isDarkMode ? '🌞' : '🌙' }}</span>
        </button>
      </nav>
    </div>
  </header>
</template>

<script>
export default {
  name: 'Header',
  data() {
    return {
      isDarkMode: false
    }
  },
  created() {
    // 从 localStorage 读取主题偏好
    const savedTheme = localStorage.getItem('theme')
    this.isDarkMode = savedTheme === 'dark'
  },
  methods: {
    toggleTheme() {
      this.isDarkMode = !this.isDarkMode
      const theme = this.isDarkMode ? 'dark' : 'light'
      
      // 保存到 localStorage
      localStorage.setItem('theme', theme)
      
      // 触发全局主题切换事件
      window.dispatchEvent(new CustomEvent('theme-change', {
        detail: { isDarkMode: this.isDarkMode }
      }))
    }
  }
}
</script>

<style scoped>
.header {
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 16px 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo a {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-primary);
  text-decoration: none;
}

.logo-img {
  width: 40px;
  height: 40px;
}

.logo-text {
  font-size: 20px;
  font-weight: 600;
}

.nav {
  display: flex;
  gap: 24px;
}

.nav-item {
  color: var(--text-secondary);
  text-decoration: none;
  padding: 8px 16px;
  border-radius: 6px;
  transition: all 0.2s ease;
  font-weight: 500;
}

.nav-item:hover {
  color: var(--text-primary);
  background-color: var(--bg-tertiary);
}

.nav-item.active {
  color: var(--primary-color);
  background-color: rgba(66, 184, 131, 0.1);
}

.theme-toggle {
  padding: 8px 12px;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 12px;
}

.theme-toggle:hover {
  background-color: var(--bg-primary);
  border-color: var(--primary-color);
  transform: scale(1.05);
}

.theme-toggle:active {
  transform: scale(0.95);
}

.theme-icon {
  font-size: 20px;
  line-height: 1;
  display: block;
}

@media (max-width: 768px) {
  .nav {
    gap: 12px;
  }
  
  .nav-item {
    padding: 6px 12px;
    font-size: 14px;
  }
  
  .theme-toggle {
    padding: 6px 10px;
    margin-left: 8px;
  }
  
  .theme-icon {
    font-size: 18px;
  }
}
</style>

